Technote 1190Power Manager 2.0 |
CONTENTS
Participating in Power Management |
The Power Manager 2.0 is an update to Mac OS that facilitates the implementation of a more aggressive power management policy, and supports new capabilities in the latest Macintosh hardware and the NewWorld ROM architecture. Power Manager 2.0 is available on all iMacs, Blue & White G3 and Power Mac G4 desktops, the "bronze keyboard" PowerBook G3 Series, the iBook, and future portables and desktops. While internal changes have been made to the Mac OS to support Power Manager 2.0, there are a few new API routines that are available to developers. Thus, this document describes the features new or updated in Power Manager 2.0. For complete details on using Power Manager services, please see the chapter "Power Manager" in Inside Macintosh: Devices. This Note is not only directed at application developers who previously had concerns about running on portables, but indeed to all Mac OS application developers. Device Driver writers on the other hand, should review Updating Drivers for PM 2.0 for detailed information on how to support removal of power to the PCI slots. |
Changes to Sleep and WakeTo meet more aggressive power management requirements, the sleep/wake process has been enhanced to permit new hardware capabilities, including removing power from the PCI slots during sleep, if possible, and entering a new state called "deep sleep." However, the overall process is the same and the use of the sleep queue remains unchanged, other than additional messages that entries may or may not need to handle. DriverServices has been updated to provide services, which, if used by PCI (and other) device drivers, allow devices to control their power during the sleep/wake process at a later stage than the traditional sleep queue. While using these new services is similar to using the classic sleep queue, the point at which device power handlers will be called is much later in the process, thereby allowing those devices to provide their services until the last possible moment before power is removed.
|
Device Power HandlersA device power handler is a routine called by the Power Manager that services power management requests on behalf of devices attached to the computer. The Power Manager defines a new low-level sleep queue called the device sleep queue. The device sleep queue is comprised of power handlers that are called with sleep-related power management requests very late in the sleep process and very early in the wake process. This queue is intended primarily for device drivers to set their power state in response to a sleep or wake event. The device sleep queue will receive the same messages sent to the traditional sleep queue, and both queues can receive some additional messages (please see "New Sleep Messages" below).
This is the definition of a power handler. The parameter
|
New Routines in Power Manager 2.0AddDevicePowerHandler
You can use
RemoveDevicePowerHandlerYou can use
GetDevicePowerLevelYou can use
SetDevicePowerLevelYou can use
|
New Sleep TypesWith Power Manager 2.0 and the latest hardware from Apple, including the iBook and later machines, there are a few variations on sleep. Simple SleepThis form of sleep is what most have come to know as traditional PowerBook sleep. Most of the machine is powered off, but memory is placed into self-refresh mode so that the contents are not lost while the machine is asleep. Safe SleepThis form of sleep is similar to simple sleep, but a file is written to disk that represents the contents of memory at the point of sleeping so that -- should an unexpected loss of power occur -- the user's working context can be fully restored upon the next startup. Currently, this variation of sleep is only available if Virtual Memory is turned on in the Memory Control Panel. Safe sleep is enabled if the user checks the "Preserve memory contents on sleep" checkbox in the Advanced Settings panel of the Energy Saver Control Panel. Deep SleepThis form of sleep is one where the contents of memory are written to disk and the machine is fully powered off. When the user presses the power key the machine is booted to the point where it is determined if the preserved memory contents exist on disk and, if so, memory is reconstructed and the machine wakes up as though it had only just slept. Deep sleep is currently only available if Virtual Memory is turned on in the Memory Control Panel. Currently, deep sleep is only entered when the machine goes into a Safe Sleep state and power is lost during that time (such as when battery power is fully drained while the machine is asleep).
To see if safe or deep sleep is a supported feature of a given
machine, use the |
Sleep MessagesGiven the variations now possible for sleep, the messages sent to the sleep queue and the device sleep queue can also vary. Messages for Simple Sleep
In this case, sleep queue entries and device sleep queue entries will
receive the standard set of messages: Messages for Safe Sleep
In the safe sleep case, the standard set of messages described above
is sent, but prior to a
On wakeup, if power was lost, then the sleep queue will receive a
Sleep Message ExamplesIn order to clarify the complexity of the new messages, the following examples are provided to show the order of events for each type of sleep. It is important to note that most software will not have to change how sleep is handled to run correctly with the new Power Manager, since most software typically should not care if safe sleep is being entered or not. In this case, follow the same guidelines as described in Inside Macintosh: Devices. Only device driver writers and those who must do something differently in the case of safe sleep need to understand when the new messages are sent and how to respond to them.
Simple Sleep Request (Idle Sleep)This is the sequence of messages sent when the user-specified sleep timeout occurs:
Simple Sleep Demand (User-Demand Sleep)This is the sequence of messages sent when the user (or a low-power condition) initiates sleep:
Safe Sleep RequestThis is the sequence of messages sent when the user-specified sleep timeout occurs for safe sleep:
Safe Sleep DemandThis is the sequence of messages sent when the user (or a low-power condition) initiates safe sleep:
|
More New MessagesWakeToDoze
The kWakeToDoze :
Sample handler that DOES handle kWakeToDoze differently:
DozeToFullWakeUp
The If the machine is in the intermediate wake state (doze) and the normal sleep timeout occurs, the sleep queue entries will get the normal sleep or suspend request messages, and should handle them accordingly as the machine goes back to full sleep. GetPowerLevel & GetPowerLevel
The DeviceInitiatedWake
The Here is an example of a function that indicates to the Power Mgr that its device caused the wakeup:
|
Wake on Network Activity
New hardware (including iBook and Power Mac G4) has a new feature
called "Wake on Network." This means that, based on user preference,
certain types of network activity will cause a sleeping computer to
awaken to respond to the network request. The user (via Energy Saver)
or developer can specify two options insofar as what network activity
can wake a sleeping machine (using the
GetWakeOnNetworkOptions
SetWakeOnNetworkOptions
Networking Drivers and Wake On NetworkDrivers that control a network interface card should be sure to register a power handler with the Power Manager (see Device Power Handlers) so that they may respond to queries about whether they caused the system to be awakened. The kGetWakeOnNetInfo message will be sent to see if the
network device that is currently selected in fact supports waking on
network activity.
The kDeviceInitiatedWake message will be sent to the
networking device's power handler upon wakeup. The power handler
should respond with a result indicating if the device which the power
handler represents is responsible for waking the system. The power
handler should return kDeviceRequestsWakeToFull if the
system should be fully awakened to service the request and
kDeviceRequestsWakeToDoze if the system should only be
partially awakened to service the request. A partially awakened
system is one that is put into the doze state instead of the full
running state.
|
Adding Power SourcesPower Manager 2.0 has the provision to control and interact with a number of devices such as AC, batteries, or UPS devices that supply power to the system. As such, the Power Manager needs to be informed of the existence and status of all attached power sources to reliably provide the user important information, particularly if the system is running on battery or backup power alone (e.g., UPS). The Power manager is made aware of the existence of these devices through the power source data structure (referred to simple as a power source). Power Source data structureThe following describes the structure of a power source:
The power source can specify how the Power Manager should interpret
the
The following power source attribute flags can be used:
The following power source state flags can be used:
AddPowerSourceYou can add a power source to the list of sources the Power
Manager monitors by calling
The client will receive a unique RemovePowerSource
If a device's power source is no longer available, you can tell the
Power Manager to remove the source from its list using
UpdatePowerSource
You can update a power source's vital statistics (power consumption
rate, capacity remaining, etc.) by calling
Example A simple UPS Power SourceLet's say the user attaches a UPS to the system that is capable of communicating its status to the Power Manager. The UPS driver software should register a power source with the Power Manager to indicate its existence:
When AC power is removed, the UPS can update the status by making the following change during its periodic update:
When the UPS specifies that no AC is present, it is an indication to the Power Manager that any internal readings about the presence of AC are invalid and, hence, the Power Manager treats the system as though it were running off battery. As a result, under low-power conditions, the system will perform the same low-power actions that it does on PowerBooks with low battery power, that is, it will put the system into a low-power state. If the system supports deep sleep, it will try to put that system into deep sleep. If not, then the system is put into normal sleep unless it doesn't normally provide battery power (as is the case with desktops) in which case the system will be powered off. Note that Apple Events will be sent to active processes to indicate when a low-power condition exists and when low-power actions are imminent. Please see "Power Manager Apple Events" below for a description of these events. |
Obtaining Microprocessor TemperatureYou can use the Power Manager to obtain the core temperature of the microprocessor or microprocessors on board.
The parameter, The temperature is expressed in degrees centigrade. The result will be a positive value if the temperature was correctly obtained. If the result is negative, then an error is being returned.
This routine will return
|
Power Manager Apple EventsThe Power Manager now provides limited support for Apple Events. Currently, only four events are broadcast to all active processes that indicate they are high-level event aware. Power Management Event Class
All events are broadcast using an event class of
Power Management Event IDsThe following event ids have been defined:
The
The
One of two emergency low-power action warnings is broadcast when the machine is about to run out of backup power. Which message is sent depends on the machine and the features it supports.
The
The
|
Server ModeThe new Power Manager provides two new routines to allow server mode operation. This mode, most useful on servers (!), allows the machine to be started automatically in the event of unexpected loss of AC power and then subsequent restoration of AC power.
You can use
You can use |
|